<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #parent{
            width: 200px;
            height: 200px;
            background-color: red;
        }
        #child{
            width: 100px;
            height: 100px;
            background-color: yellowgreen
        }
    </style>
</head>
<body>
    <div id="parent">
        <div id="child">

        </div>
    </div>
    <!-- 事件冒泡：给父元素和子元素绑定相同的事件。子元素执行事件的时候父元素的事件 也会执行 -->
    <script>
        var parent = document.getElementById('parent');
        var child = document.getElementById('child');
        // parent.onclick = function(){
        //     alert('parent')
        // }
        // child.onclick = function(e){
        //     alert('child')
        //     e.stopPropagation()
        // }

        //addEventListener(eventName,callback,bubbling==false(default))
        parent.addEventListener("click",function(){
            alert('parent')
        },false)
        child.addEventListener("click",function(){
            alert('child')
        },false)
    </script>
</body>
</html>